|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
MemoryBPELProcessDAO.java | 100% | 100% | 100% | 100% |
|
1 |
/*
|
|
2 |
* $Id: MemoryBPELProcessDAO.java,v 1.1 2004/12/15 14:18:09 patforna Exp $
|
|
3 |
*
|
|
4 |
* Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
|
|
5 |
* Berne University of Applied Sciences
|
|
6 |
* School of Engineering and Information Technology
|
|
7 |
* All rights reserved.
|
|
8 |
*/
|
|
9 |
package bexee.dao;
|
|
10 |
|
|
11 |
import java.util.HashMap;
|
|
12 |
import java.util.Map;
|
|
13 |
|
|
14 |
import bexee.model.process.BPELProcess;
|
|
15 |
|
|
16 |
/**
|
|
17 |
* This class uses memory rather than persistent storage to store and load
|
|
18 |
* <code>BPELProcess</code> objects.
|
|
19 |
*
|
|
20 |
* @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:09 $
|
|
21 |
* @author Patric Fornasier
|
|
22 |
* @author Pawel Kowalski
|
|
23 |
*/
|
|
24 |
public class MemoryBPELProcessDAO implements BPELProcessDAO { |
|
25 |
|
|
26 |
protected static Map map; |
|
27 |
|
|
28 |
/**
|
|
29 |
* Creates a new <code>MemoryBPELProcessDAO</code> that uses a static
|
|
30 |
* <code>Map</code> to manage the stored <code>BPELProcess</code>
|
|
31 |
* objects.
|
|
32 |
*/
|
|
33 | 32 |
public MemoryBPELProcessDAO() {
|
34 | 32 |
if (map == null) { |
35 | 8 |
map = new HashMap();
|
36 |
} |
|
37 |
} |
|
38 |
|
|
39 | 4 |
public void delete(String name) { |
40 | 4 |
map.remove(name); |
41 |
} |
|
42 |
|
|
43 | 4 |
public void deleteAll() { |
44 | 4 |
map.clear(); |
45 |
} |
|
46 |
|
|
47 | 44 |
public BPELProcess find(String name) {
|
48 | 44 |
return (BPELProcess) map.get(name);
|
49 |
} |
|
50 |
|
|
51 | 12 |
public String insert(BPELProcess process) {
|
52 |
|
|
53 |
// generate id and set it on BPEL process
|
|
54 | 12 |
String name = process.getName(); |
55 |
|
|
56 |
// store BPEL process and return id
|
|
57 | 12 |
map.put(name, process); |
58 | 12 |
return name;
|
59 |
} |
|
60 |
|
|
61 | 8 |
public void update(BPELProcess process) throws DAOException { |
62 |
|
|
63 |
// check if we have that object already
|
|
64 | 8 |
String name = process.getName(); |
65 | 8 |
BPELProcess oldProcess = find(name); |
66 | 8 |
if (oldProcess == null) { |
67 | 2 |
throw new DAOException("No object with id " + name + " to update"); |
68 |
} |
|
69 |
|
|
70 |
// replace with new version
|
|
71 | 6 |
map.put(name, process); |
72 |
|
|
73 |
} |
|
74 |
|
|
75 | 8 |
public String replace(BPELProcess process) throws DAOException { |
76 |
|
|
77 |
// check if we have that object already
|
|
78 | 8 |
String name = process.getName(); |
79 | 8 |
BPELProcess oldProcess = find(name); |
80 |
|
|
81 | 8 |
if (oldProcess != null) { |
82 | 4 |
update(process); |
83 |
} else {
|
|
84 | 4 |
name = insert(process); |
85 |
} |
|
86 |
|
|
87 | 8 |
return name;
|
88 |
} |
|
89 |
} |
|